#导包
from configparser import ConfigParser
import os

#定义类
class ReadConfig:
    #定义初始化方法
    def __init__(self):
        self.path = os.path.dirname(os.path.dirname(__file__)) + r"/config.ini"
        self.conf = ConfigParser()
        self.conf.read(self.path,encoding="utf-8")

    # def get_section(self,section):
    #     return self.conf.items(section)

    # def get_option(self,section,option):
    #     return self.conf.get(section,option)


    #优化
    def get_config(self,section,option="all"):
        if option == "all":
            return self.conf.items(section)
        else:
            return self.conf.get(section,option)



if __name__ == '__main__':
    cp = ReadConfig()
    # print(cp.get_section("mysql"))
    # print(cp.get_option("redis","port"))

    #优化
    print(cp.get_config("mysql"))
    print(cp.get_config("redis","port"))